/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.ui.beans;

import com.pos.domain.ItemCategory;
import com.pos.services.BaseService;
import com.pos.ui.jsf.util.JsfUtil;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.model.SelectItem;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author suraj
 */
@Named("categoryBean")
@RequestScoped
public class CategoryBean implements Serializable {

    @Inject
    private transient BaseService baseService;
    private ItemCategory category;
    private boolean editMode;

    public ItemCategory getCategory() {
        return category;
    }

    @PostConstruct
    public void reset() {
        this.category = new ItemCategory();
    }

    public SelectItem[] getCategoryItems() {
        return JsfUtil.getSelectItems(baseService.findAllCatagory(), false);
    }

    public List<ItemCategory> getCategories() {
        return baseService.findAllCatagory();
    }

    public void save() {
        baseService.saveCategory(category);
        reset();
        setEditMode(false);
    }

    public void edit(Object id) {
        this.category = baseService.findCategoryById(id);
        setEditMode(true);
    }

    public void createNewCategory() {
//        this.category = new ItemCategory();
        setEditMode(true);
    }

    public void setEditMode(boolean editMode) {
        this.editMode = editMode;
    }

    public boolean isEditMode() {
        return this.editMode;
    }
}
